﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace VoxelBlock
{
    /// <summary>
    /// byte向量
    /// </summary>
    struct Vector3Byte
    {
        public byte x;
        public byte y;
        public byte z;

        public Vector3Byte(byte x, byte y, byte z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public Vector3Byte(int x, int y, int z)
        {
            this.x = (byte)x;
            this.y = (byte)y;
            this.z = (byte)z;
        }

        public Vector3Byte(float x, float y, float z)
        {
            this.x = (byte)x;
            this.y = (byte)y;
            this.z = (byte)z;
        }

        public Vector3Byte(short x, short y, short z)
        {
            this.x = (byte)x;
            this.y = (byte)y;
            this.z = (byte)z;
        }

        #region 继承方法
        public override bool Equals(object b)
        {
            if (b is Vector3Byte)
            {
                var v = (Vector3Byte)b;
                return this.x == v.x && this.y == v.y && this.z == v.z;
            }
            else if (b is Vector3Int)
            {
                var v = (Vector3Int)b;
                return this.x == (byte)v.x && this.y == (byte)v.y && this.z == (byte)v.z;
            }
            else if (b is Vector3)
            {
                var v = (Vector3)b;
                return this.x == (byte)v.x && this.y == (byte)v.y && this.z == (byte)v.z;
            }
            return false;
        }

        public override int GetHashCode()
        {
            return (this.x + 512) + ((this.y + 512) << 0x0A) + (this.z << 0x14);
        }

        public override string ToString()
        {
            return this.x + "," + this.y + "," + this.z;
        }
        #endregion

        #region 运算符重载
        /// <summary>
        /// 两个向量相加
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector3Byte operator +(Vector3Byte a, Vector3Byte b)
        {
            return new Vector3Byte(a.x + b.x, a.y + b.y, a.z + b.z);
        }

        /// <summary>
        /// 两个向量相减
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector3Byte operator -(Vector3Byte a, Vector3Byte b)
        {
            return new Vector3Byte(a.x - b.x, a.y - b.y, a.z - b.z);
        }

        /// <summary>
        /// 两个向量相乘
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector3Byte operator *(Vector3Byte a, Vector3Byte b)
        {
            return new Vector3Byte(a.x * b.x, a.y * b.y, a.z * b.z);
        }

        /// <summary>
        /// 两个向量相除
        /// </summary>
        /// <param name="b"></param>
        /// <param name="a"></param>
        /// <returns></returns>
        public static Vector3Byte operator /(Vector3Byte b, Vector3Byte a)
        {
            return new Vector3Byte(a.x / b.x, a.y / b.y, a.z / b.z);
        }


        public static Vector3Byte operator +(Vector3Byte a, int b)
        {
            return new Vector3Byte(a.x + b, a.y + b, a.z + b);
        }
        public static Vector3Byte operator +(int b, Vector3Byte a)
        {
            return new Vector3Byte(a.x + b, a.y + b, a.z + b);
        }

        public static Vector3Byte operator -(Vector3Byte a, int b)
        {
            return new Vector3Byte(a.x - b, a.y - b, a.z - b);
        }
        public static Vector3Byte operator -(int b, Vector3Byte a)
        {
            return new Vector3Byte(a.x - b, a.y - b, a.z - b);
        }

        public static Vector3Byte operator *(Vector3Byte a, int b)
        {
            return new Vector3Byte(a.x * b, a.y * b, a.z * b);
        }
        public static Vector3Byte operator *(int b, Vector3Byte a)
        {
            return new Vector3Byte(a.x * b, a.y * b, a.z * b);
        }

        public static Vector3Byte operator /(Vector3Byte a, int b)
        {
            return new Vector3Byte(a.x / b, a.y / b, a.z / b);
        }
        public static Vector3Byte operator /(int b, Vector3Byte a)
        {
            return new Vector3Byte(a.x / b, a.y / b, a.z / b);
        }


        #endregion

        #region 隐式转换
        public static implicit operator Vector3(Vector3Byte v)
        {
            return new Vector3(v.x, v.y, v.z);
        }
        public static implicit operator Vector3Byte(Vector3 v)
        {
            return new Vector3Byte(v.x, v.y, v.z);
        }
        public static implicit operator Vector3Int(Vector3Byte v)
        {
            return new Vector3Int(v.x, v.y, v.z);
        }
        public static implicit operator Vector3Byte(Vector3Int v)
        {
            return new Vector3Byte(v.x, v.y, v.z);
        }
        #endregion
    }
}